
********************************************************************************
************************** CREATE CODED DATA FILES *****************************
********************************************************************************


* Note: Load in each original dataset before running the associated code section.


********************************************************************************
*****************************  LUCID 2020 DATA  ******************************** 
********************************************************************************

*import excel "", sheet("Sheet0") firstrow clear

************ Data Quality ************

* Drop If: Fail Bot Check, Non-Consent, Fail Attention Check
drop if bot != "5,6"
drop if IC != 4
drop if attn != "2,3"


************ Demographics ************ 

* Gender
gen male = .
replace male = 1 if gender == 1
replace male = 0 if gender == 2 | gender == 3

* Race/Ethnicity Dummies
gen black = .
replace black = 1 if ethnicity_lucid == "2" 
replace black = 0 if ethnicity_lucid != "2"

gen hispanic = .
replace hispanic = 1 if hispanic_lucid != "1"
replace hispanic = 0 if hispanic_lucid == "1"

* Education 
gen educ01 = .
replace educ01 = (educ-1)/5

* Impute Lucid Embedded Data for Missings
gen educ_impute = .
replace educ_impute = 0 if education_lucid == "1"
replace educ_impute = .2 if education_lucid == "2"
replace educ_impute = .4 if education_lucid == "3" | education_lucid == "4" 
replace educ_impute = .6 if education_lucid == "5"
replace educ_impute = .8 if education_lucid == "6"
replace educ_impute = 1 if education_lucid == "7" | education_lucid == "8" 

replace educ01 = educ_impute if educ01 == .

* Unemployed
gen unemp = .
replace unemp = 1 if employ == 3
replace unemp = 0 if employ != 3

* Age
gen age01 = .
replace age01 = (age-18)/72

* Income 
gen income01 = .
replace income01 = (income-1)/12

* Region
gen region4 = .
replace region4 = 1 if region_lucid == "1"
replace region4 = 2 if region_lucid == "2"
replace region4 = 3 if region_lucid == "3"
replace region4 = 4 if region_lucid == "4"

gen south = .
replace south = 1 if region4 == 3
replace south = 0 if region4 != 3


************ Political Engagement ************

* Attention to Politics Scale
replace attention = (attention-1)/4
replace news = (news)/7

alpha attention news, gen(polattn_scale) item

* Political Knowledge Scale
gen kn1_correct = .
replace kn1_correct = 1 if kn1 == 1
replace kn1_correct = 0 if kn1 != 1
gen kn2_correct = .
replace kn2_correct = 1 if kn2 == 3
replace kn2_correct = 0 if kn2 != 3
gen kn3_correct = .
replace kn3_correct = 1 if kn3 == 3
replace kn3_correct = 0 if kn3 != 3
gen kn4_correct = .
replace kn4_correct = 1 if kn4 == 2
replace kn4_correct = 0 if kn4 != 2
gen kn5_correct = .
replace kn5_correct = 1 if kn5 == 2
replace kn5_correct = 0 if kn5 != 2
gen kn6_correct = .
replace kn6_correct = 1 if kn6 == 1
replace kn6_correct = 0 if kn6 != 1

alpha kn1_correct kn2_correct kn3_correct kn4_correct kn5_correct kn6_correct, gen(polknow_scale) item

* Political Engagement Scale 
alpha polattn_scale polknow_scale, gen(engagement) item


************ Authoritarianism Scale ************

gen auth1_rc = .
replace auth1_rc = 1 if auth1 == 2
replace auth1_rc = 0 if auth1 == 1
gen auth2_rc = .
replace auth2_rc = 1 if auth2 == 2
replace auth2_rc = 0 if auth2 == 1
gen auth3_rc = .
replace auth3_rc = 1 if auth3 == 1
replace auth3_rc = 0 if auth3 == 2
gen auth4_rc = .
replace auth4_rc = 1 if auth4 == 2
replace auth4_rc = 0 if auth4 == 1
gen auth5_rc = .
replace auth5_rc = 1 if auth5 == 1
replace auth5_rc = 0 if auth5 == 2

alpha auth1_rc auth2_rc auth3_rc auth4_rc auth5_rc, gen(auth_scale) item


************ Public Health Index ************

replace dv_businesses = 1-(dv_businesses-1)/6
replace dv_lockdowns = 1-(dv_lockdowns-1)/6
gen dv_maskmandates = .
replace dv_maskmandates = 1-(dv_masks-1)/6
replace dv_tracking = 1-(dv_tracking-1)/6

alpha dv_businesses dv_lockdowns dv_maskmandates dv_tracking, gen(publichealth_scale) item


************ Economic Intervention Index ************ 

replace dv_stimulus = 1-(dv_stimulus-1)/6
replace dv_unemp = 1-(dv_unemp-1)/6
gen dv_ppp = .
replace dv_ppp = 1-(ppp_control-1)/6 if dv_ppp == .
replace dv_ppp = 1-(ppp_stereo-1)/6 if dv_ppp == .
replace dv_ppp = 1-(ppp_counter-1)/6 if dv_ppp == .

alpha dv_stimulus dv_unemp dv_ppp, gen(econ_scale) item


************ Health Behaviors Index ************ 

* Social Distancing (Qualtrics Scoring Errors)
gen dv_distancing = .
replace dv_distancing = 1-(distancing-11)/4

* Mask-Wearing
gen dv_masking = .
replace dv_masking = 1-(maskwearing-1)/4

alpha dv_distancing dv_masking, gen(behavior_scale) item


************ Political Variables ************ 

* Partisanship
gen pid7 = .
replace pid7 = 1 if dstr == 1
replace pid7 = 2 if dstr == 2
replace pid7 = 3 if lean == 3
replace pid7 = 4 if lean == 4
replace pid7 = 5 if lean == 5
replace pid7 = 6 if rstr == 6
replace pid7 = 7 if rstr == 7

gen pid01 = .
replace pid01 = (pid7-1)/6

gen democrat = .
replace democrat = 1 if pid7 == 1 | pid7 == 2 | pid7 == 3
replace democrat = 0 if pid7 == 4 | pid7 == 5 | pid7 == 6 | pid7 == 7

gen republican = .
replace republican = 1 if pid7 == 5 | pid7 == 6 | pid7 == 7
replace republican = 0 if pid7 == 1 | pid7 == 2 | pid7 == 3 | pid7 == 4

* Ideology
replace ideo = (ideo-1)/6

* Left-Right Orientation Scale 
alpha pid01 ideo, gen(dv_leftright)


**** SUMMARY STATISTICS FOR KEY MEASURES ****
summarize engagement auth_scale publichealth_scale behavior_scale econ_scale



********************************************************************************
*************************** LUCID 2021 DATA  *********************************** 
********************************************************************************

*import excel "", sheet("Sheet0") firstrow clear

************ Data Quality Filtering ************

* Drop If: Fail Bot Check, Non-Citizen, Non-Adult, Non-Consent, Fail Attention Check
drop if bot != "5,6"
drop if citizen == 2
drop if adult == 2
drop if IC == 2
drop if attn != "2,3"
* Note: The first half of this survey included questions for another project.
drop if Duration < 180 

************ Demographic Variables ************ 

* Gender
gen male = .
replace male = 1 if gender == 1
replace male = 0 if gender == 2 | gender == 3

* Impute Lucid Embedded Data for Missings
gen male_impute = .
replace male_impute = 1 if gender_lucid == "1"
replace male_impute = 0 if gender_lucid == "2"

replace male = male_impute if male == .

* Race/Ethnicity Dummies
gen black = .
replace black = 1 if ethnicity_lucid == "2" 
replace black = 0 if ethnicity_lucid != "2"

gen hispanic = .
replace hispanic = 1 if hispanic_lucid != "1"
replace hispanic = 0 if hispanic_lucid == "1"

* Education 
gen educ01 = .
replace educ01 = (educ-1)/5

* Impute Lucid Embedded Data for Missings
gen educ_impute = .
replace educ_impute = 0 if education_lucid == "1"
replace educ_impute = .2 if education_lucid == "2"
replace educ_impute = .4 if education_lucid == "3" | education_lucid == "4" 
replace educ_impute = .6 if education_lucid == "5"
replace educ_impute = .8 if education_lucid == "6"
replace educ_impute = 1 if education_lucid == "7" | education_lucid == "8" 

replace educ01 = educ_impute if educ01 == .

* Unemployed
gen unemp = .
replace unemp = 1 if employ == 3
replace unemp = 0 if employ != 3

* Age
destring age_lucid, replace
replace age = age_lucid if age == .
gen age01 = .
replace age01 = (age_lucid-18)/74

* Income 
gen income01 = .
replace income01 = (income-1)/12

* Impute Lucid Embedded Data for Missings
destring hhi_lucid, replace
gen income_impute = .
replace income_impute = (hhi_lucid-1)/23 if hhi_lucid > 0

replace income01 = income_impute if income01 == .

* Region
gen region4 = .
replace region4 = 1 if region_lucid == "1"
replace region4 = 2 if region_lucid == "2"
replace region4 = 3 if region_lucid == "3"
replace region4 = 4 if region_lucid == "4"

gen south = .
replace south = 1 if region4 == 3
replace south = 0 if region4 != 3


************ Political Engagement ************

* Attention to Politics Scale
replace attention = (attention-1)/4
replace news = (news)/7

alpha attention news, gen(polattn_scale)

* Political Knowledge Scale
gen kn1_correct = .
replace kn1_correct = 1 if kn1 == 1
replace kn1_correct = 0 if kn1 != 1
gen kn2_correct = .
replace kn2_correct = 1 if kn2 == 3
replace kn2_correct = 0 if kn2 != 3
gen kn3_correct = .
replace kn3_correct = 1 if kn3 == 3
replace kn3_correct = 0 if kn3 != 3
gen kn4_correct = .
replace kn4_correct = 1 if kn4 == 1
replace kn4_correct = 0 if kn4 != 1
gen kn5_correct = .
replace kn5_correct = 1 if kn5 == 4
replace kn5_correct = 0 if kn5 != 4

alpha kn1_correct kn2_correct kn3_correct kn4_correct kn5_correct, gen(polknow_scale)

* Political Engagement Scale 
alpha polattn_scale polknow_scale, gen(engagement)


************ Authoritarianism Scale ************

gen auth1_rc = .
replace auth1_rc = 1 if auth1 == 2
replace auth1_rc = 0 if auth1 == 1
gen auth2_rc = .
replace auth2_rc = 1 if auth2 == 2
replace auth2_rc = 0 if auth2 == 1
gen auth3_rc = .
replace auth3_rc = 1 if auth3 == 1
replace auth3_rc = 0 if auth3 == 2
gen auth4_rc = .
replace auth4_rc = 1 if auth4 == 2
replace auth4_rc = 0 if auth4 == 1
gen auth5_rc = .
replace auth5_rc = 1 if auth5 == 1
replace auth5_rc = 0 if auth5 == 2
gen auth6_rc = .
replace auth6_rc = 1 if auth6 == 2
replace auth6_rc = 0 if auth6 == 1
gen auth7_rc = .
replace auth7_rc = 1 if auth7 == 1
replace auth7_rc = 0 if auth7 == 2
gen auth8_rc = .
replace auth8_rc = 1 if auth8 == 1
replace auth8_rc = 0 if auth8 == 2

alpha auth1_rc auth2_rc auth3_rc auth4_rc auth5_rc auth6_rc auth7_rc auth8_rc, gen(auth_scale)

************ Public Health Index  ************

replace dv_businesses = 1-(dv_businesses-1)/6
replace dv_lockdowns = 1-(dv_lockdowns-1)/6
replace dv_mmindoors = 1-(dv_mmindoors-1)/6
replace dv_mmoutdoors = 1-(dv_mmoutdoors-1)/6
replace dv_tracking = 1-(dv_tracking-1)/6
replace dv_vaxmandate = 1-(dv_vaxmandate)/6

alpha dv_mmindoors dv_mmoutdoors, gen(dv_maskmandates)

alpha dv_businesses dv_lockdowns dv_maskmandates dv_tracking dv_vaxmandate, gen(publichealth_scale)

************ Economic Intervention Index ************ 

replace dv_unemp = 1-(dv_unemp-1)/4
replace dv_rent = 1-(dv_rent-1)/6

* Fix Qualtrics Scoring Error for Inflation Item
gen dv_inflation_rc = .
replace dv_inflation_rc = 1 if dv_inflation == 1
replace dv_inflation_rc = 2 if dv_inflation == 2
replace dv_inflation_rc = 3 if dv_inflation == 3
replace dv_inflation_rc = 4 if dv_inflation == 6
replace dv_inflation_rc = 5 if dv_inflation == 7

replace dv_inflation = 1-(dv_inflation_rc-1)/4

alpha dv_unemp dv_rent dv_inflation, gen(econ_scale)

************ Health Behaviors Index ************ 

* Social Distancing (Qualtrics Scoring Errors)
gen dv_distancingindoors = .
replace dv_distancingindoors = 1-(dv_distancing1-11)/4

gen dv_distancingoutdoors = .
replace dv_distancingoutdoors = 1-(dv_distancing2-11)/4

alpha dv_distancingindoors dv_distancingoutdoors, gen(dv_distancing)

* Mask-Wearing
replace dv_maskindoors = 1-(dv_maskindoors-1)/4
replace dv_maskoutdoors = 1-(dv_maskoutdoors-1)/4

alpha dv_maskindoors dv_maskoutdoors, gen(dv_masking)

alpha dv_distancing dv_masking, gen(behavior_scale)

* Vaccine Status
gen dv_vaccinated = .
replace dv_vaccinated = 1 if dv_vaxstatus == 1 | dv_vaxstatus == 2
replace dv_vaccinated = 0 if dv_vaxstatus == 3

* Tested Positive?
replace covid_positive = 0 if covid_positive == 2

* Suspected or Tested Positive for COVID?
gen covid_posandsus = 0
replace covid_posandsus = 1 if covid_positive == 1 | covid_suspected == 1

************ Political Variables ************ 

* Partisanship
gen pid7 = .
replace pid7 = 1 if dstr == 1
replace pid7 = 2 if dstr == 2
replace pid7 = 3 if lean == 3
replace pid7 = 4 if lean == 4
replace pid7 = 5 if lean == 5
replace pid7 = 6 if rstr == 6
replace pid7 = 7 if rstr == 7

gen pid01 = .
replace pid01 = (pid7-1)/6

gen democrat = .
replace democrat = 1 if pid7 == 1 | pid7 == 2 | pid7 == 3
replace democrat = 0 if pid7 == 4 | pid7 == 5 | pid7 == 6 | pid7 == 7

gen republican = .
replace republican = 1 if pid7 == 5 | pid7 == 6 | pid7 == 7
replace republican = 0 if pid7 == 1 | pid7 == 2 | pid7 == 3 | pid7 == 4

* Ideology
replace ideo = (ideo-1)/6

* Left-Right Orientation Scale 
alpha pid01 ideo, gen(dv_leftright)


**** SUMMARY STATISTICS FOR KEY MEASURES ****
summarize engagement auth_scale publichealth_scale behavior_scale dv_vaccinat econ_scale


********************************************************************************
******************************** ANES-GSS **************************************
********************************************************************************

*use "", clear

* Sampling Variables
gen weight = .
replace weight = V200018b

*Remove Those Who Weren't Part of GSS
drop if samptype == .

* Year of Wave 1 Interview
gen year = .
replace year = 2016 if samptype == 2016
replace year = 2018 if samptype == 2018
label variable year "Year of Wave 1 Interview"

* Reinterviewed in 2020?
gen reinterviewed = .
replace reinterviewed = 1 if panstat == 1
replace reinterviewed = 0 if panstat != 1
drop if reinterviewed != 1
label variable reinterviewed "Reinterviewed in 2020?"

* US Citizen 
gen citizen_t2 = .
replace citizen_t2 = 1 if born_2 == 1
replace citizen_t2 = 1 if (uscitzn_2 == 1 | uscitzn_2 == 3 | uscitzn_2 == 4)
* Drop if non-citizen in second wave
drop if citizen_t2 != 1

* Age
gen age = .
replace age = (age_1a-18)/71 if year == 2016
replace age = (age_1b-18)/71 if year == 2018
label variable age "Age Scale 0 to 1"

* Gender
gen male_t1 = .
replace male_t1 = 1 if sex_1a == 1 & year == 2016
replace male_t1 = 0 if sex_1a == 2 & year == 2016
replace male_t1 = 1 if sex_1b == 1 & year == 2018
replace male_t1 = 0 if sex_1b == 2 & year == 2018
gen male_t2 = .
replace male_t2 = 1 if sex_2 == 1
replace male_t2 = 0 if sex_2 == 2
* Impute T1/T2 Sex Based on T2/T1 Sex
replace male_t1 = male_t2 if male_t1 == .
replace male_t2 = male_t1 if male_t2 == . & reinterviewed == 1
gen male = male_t2

* Race/Ethnicity
gen race_t1 = .
replace race_t1 = 1 if race_1a == 1 & hispanic_1a == 1 & year == 2016
replace race_t1 = 1 if race_1b == 1 & hispanic_1b == 1 & year == 2018
replace race_t1 = 2 if race_1a == 2 & hispanic_1a == 1 & year == 2016
replace race_t1 = 2 if race_1b == 2 & hispanic_1b == 1 & year == 2018
replace race_t1 = 3 if hispanic_1a > 1 & hispanic_1a <= 50 & year == 2016
replace race_t1 = 3 if hispanic_1b > 1 & hispanic_1b <= 50 & year == 2018
replace race_t1 = 4 if race_1a == 3 & hispanic_1a == 1 & year == 2016
replace race_t1 = 4 if race_1b == 3 & hispanic_1b == 1 & year == 2018
label variable race_t1 "Race 4-Categories"
label define racel 1 "White, Non-Hispanic" 2 "Black, Non-Hispanic" 3 "Hispanic" 4 "Other Race" 
label values race_t1 racel
gen white = .
replace white = 1 if race_t1 == 1
replace white = 0 if race_t1 == 2 | race_t1 == 3 | race_t1 == 4
gen black = .
replace black = 1 if race_t1 == 2
replace black = 0 if race_t1 == 1 | race_t1 == 3 | race_t1 == 4
gen hispanic = .
replace hispanic = 1 if race_t1 == 3
replace hispanic = 0 if race_t1 == 1 | race_t1 == 2 | race_t1 == 4
gen otherrace = .
replace otherrace = 1 if race_t1 == 4
replace otherrace = 0 if race_t1 == 1 | race_t1 == 2 | race_t1 == 3
label variable white "White, Non-Hispanic"
label variable black "Black, Non-Hispanic"
label variable hispanic "Hispanic"
label variable otherrace "Other Race"
gen race = race_t1

* Unemployed?
gen unemp = .
replace unemp = 1 if wrkstat_2 == 4 
replace unemp = 0 if wrkstat_2 >= 1 & wrkstat_2 <10 & wrkstat_2 != 4 

* Education 
gen educ_t1 = . 
replace educ_t1 = degree_1a/4 if year == 2016
replace educ_t1 = degree_1b/4 if year == 2018
gen educ_t2 = .
replace educ_t2 = degree_2/4
* Impute T1/T2 Education Based on T2/T1 Education
replace educ_t1 = educ_t2 if educ_t1 == .
replace educ_t2 = educ_t1 if educ_t2 == . & reinterviewed == 1
gen education = educ_t2

* Region
gen region_t2 = .
replace region_t2 = 1 if (region_2 == 1 | region_2 == 2 ) 
replace region_t2 = 2 if (region_2 == 3 | region_2 == 4 ) 
replace region_t2 = 3 if (region_2 == 5 | region_2 == 6 | region_2 == 7) 
replace region_t2 = 4 if (region_2 == 8 | region_2 == 9 ) 
label variable region_t2 "Census Region"
label values region_t2 regionl
gen south = 0
replace south = 1 if region_t2 == 3

* Married
gen married = 0
replace married = 1 if marital_2 == 1 

* Income 
gen income_t1 = .
replace income_t1 = (income16_1a - 1)/25 if year == 2016
replace income_t1 = (income16_1b - 1)/25 if year == 2018
gen income_t2 = .
replace income_t2 = (income16_2 - 1)/26
impute income_t2 income_t1 age male education black hispanic married, gen(income)

* Party and Ideology
gen pid01_t2 = .
replace pid01_t2 = partyid_2/6 if partyid_2 < 7 
replace pid01_t2 = .5 if partyid_2 == 7 

gen ideo01_t2 = .
replace ideo01_t2 = (polviews_2-1)/6 
replace ideo01_t2 = .5 if polviews_2 == .d

egen dv_leftright = rmean(pid01_t2 ideo01_t2)

* AUTHORITARIANISM 
gen auth1 = .
replace auth1 = 1 if V202266 == 2
replace auth1 = .5 if V202266 == 3
replace auth1 = 0 if V202266 == 1
gen auth2 = .
replace auth2 = 1 if V202267 == 2
replace auth2 = .5 if V202267 == 3
replace auth2 = 0 if V202267 == 1
gen auth3 = .
replace auth3 = 1 if V202268 == 1
replace auth3 = .5 if V202268 == 3
replace auth3 = .5 if V202268 == 4
replace auth3 = 0 if V202268 == 2
gen auth4 = .
replace auth4 = 1 if V202269 == 2
replace auth4 = .5 if V202269 == 3
replace auth4 = 0 if V202269 == 1

alpha auth1 auth2 auth3 auth4, generate(auth_scale)

* Political Knowledge (Note, first three knowledge items on pre-election wave)
gen know4 = .
replace know4 = 1 if V202138y == 1
replace know4 = 0 if V202138y == 0 | V202138y == -9
gen know5 = .
replace know5 = 1 if V202139y1 == 1
replace know5 = 0 if V202139y1 == 0 | V202139y1 == -9
gen know6 = .
replace know6 = 1 if V202140y1 == 1
replace know6 = 0 if V202140y1 == 0 | V202140y1 == -9
gen know7 = .
replace know7 = 1 if V202141y1 == 1
replace know7 = 0 if V202141y1 == 0 | V202141y1 == -9
gen know8 = .
replace know8 = 1 if V202142y2 == 1
replace know8 = 0 if V202142y2 == 0 | V202142y2 == -9

alpha know4-know8, generate(knowledge)
gen engagement = knowledge

gen know_high = .
replace know_high = 1 if knowledge >= .5
replace know_high = 0 if knowledge < .5

* Concern over COVID-19
gen covidconcern = .
replace covidconcern = 1-(wrycovid_2-1)/4 






